<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_CUSTOMER_MNG;

require "../framepages/moudle_base.php";
$customer_id = $_GET['customer_id'];
$date = date("Y-m");
?>
<div class="main-content">
    <div>
        <span><h2>询价记录</h2></span>
    </div>
    <div>
        <table class="table" style="word-break:break-all">
            <tr>
                <th width="2%">序号</th>
                <th width="3%">品种名称</th>
                <th width="3%">规格名称</th>
                <th width="3%">规格参数</th>
                <th width="2%">单位</th>
                <th width="3%">省</th>
                <th width="3%">市</th>
                <th width="3%">区/县</th>
                <th width="3%">价格</th>
                <th width="4%">询价时间</th>
            </tr>
            <?php
            $page_index = $_GET['page_index'];
            if (!$page_index) {
                $page_index = 1;
            }
            $every_page_counts = 30;
            $list_start = ($page_index-1)*$every_page_counts;
            $customer_action_log_list_array = \Data\Tree_customer_action_log_DAO::getListByCustomerId($customer_id,$date,$list_start,$every_page_counts);
            $customer_action_log_list = $customer_action_log_list_array[1];
            $total_count = $customer_action_log_list_array[0];
            $page_count = ceil($total_count/$every_page_counts);
            $page_last = $page_index-1;
            $page_next = $page_index+1;
            $i = $list_start+1;
            $i = 1;
            foreach ($customer_action_log_list as $customer_action_log_record) {
                $customer_id = $customer_action_log_record->getCUSTOMER_ID();
                $productor_id = $customer_action_log_record->getPRODUCTOR_ID();
                $created_on_vist = $customer_action_log_record->getCREATED_ON();
                $productor_record = \Data\Tree_productor_DAO::getRecord($productor_id);
                if ($productor_record) {
                    $species_id = $productor_record->getSPECIES_ID();
                    $species_record = \Data\Tree_species_DAO::getRecord($species_id);
                    $species_name = $species_record->getSPECIES_NAME();
                    $dw = $species_record->getDW();

                    $gg_id = $productor_record->getGG_ID();
                    $gg_record = \Data\Tree_gg_DAO::getRecord($gg_id);
                    $gg_name = $gg_record->getGG_NAME();
                    $gg_dw = $gg_record->getGG_DW();
                    $gg_full_name = $gg_name."($gg_dw)";

                    $gg_cs = $productor_record->getGG_CS();
                    $province = $productor_record->getPROVINCE();
                    $city = $productor_record->getCITY();
                    $county = $productor_record->getCOUNTY();
                    $price = $productor_record->getPRICE();
                    $visit_count = $productor_record->getVISIT_COUNT();

                    echo "
                        <tr>
                            <td>$i</td>
                            <td>$species_name</td>
                            <td>$gg_full_name</td>
                            <td>$gg_cs</td>
                            <td>$dw</td>
                            <td>$province</td>
                            <td>$city</td>
                            <td>$county</td>
                            <td>$price</td>
                            <td>$created_on_vist</td>
                        </tr>
                    ";
                    $i++;
                }

            }
            ?>
        </table>
    </div>

    <div style="margin-left:35%; margin-top:40px;">
        <div>
            <?php
            if ($page_last) {
                echo "            
                    <button onclick='last_page($page_last)'>上一页</button>                            
                ";
            }

            if ($page_next<=$page_count) {
                echo "         
                    <button onclick='next_page($page_next)'>下一页</button>               
                ";
            }

            if ($page_count>1) {
                echo "
                    &nbsp;&nbsp;&nbsp;&nbsp;去往第<input type='text' name='go_page' id='go_page' size='3'>页
                <button onclick='go_page()'>GO</button>
                    ";
            }
            ?>



        </div>

        <div style="margin-left:5%; margin-top:20px;">
            第<?php echo $page_index ?>页 &nbsp;&nbsp;&nbsp;&nbsp;
            共<?php echo $page_count ?>页  &nbsp;&nbsp;&nbsp;&nbsp;共<?php echo $total_count ?>条记录
        </div>


    </div>


    <?php
    require "../framepages/footer.php";
    ?>
</div>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>

<script>

    function last_page(page_last) {
        needle = $('#4sStoreName').val();
        url = "?page_index="+page_last+"&needle"+needle+"&customer_id="+"<?php echo $customer_id ?>";
        window.location.href = url;
    }

    function next_page(page_next) {
        needle = $('#4sStoreName').val();
        url = "?page_index="+page_next+"&needle"+needle+"&customer_id="+"<?php echo $customer_id ?>";
        window.location.href = url;
    }

    function go_page()
    {
        needle = $('#4sStoreName').val();
        url = "?page_index="+$('#go_page').val()+"&needle"+needle+"&customer_id="+"<?php echo $customer_id ?>";
        window.location.href = url;
    }
</script>
</body>
</html>
